package org.ms.mconf.server.springboot.controller;

import org.ms.mconf.sdk.model.MetaConfig;
import org.ms.mconf.sdk.model.MetaDataConfig;
import org.ms.mconf.sdk.model.NodeConfig;
import org.ms.mconf.sdk.model.NodeMultiConfig;
import org.ms.mconf.server.springboot.BaseApi;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Controller
public class WebController extends BaseApi {

    @RequestMapping("/")
    public String index(HashMap<String, Object> map) {
        map.put("hello", "欢迎进入HTML页面");
        return "index";
    }

    @RequestMapping("main")
    public String main(HashMap<String, Object> map) {
        return "main";
    }

    @RequestMapping("node-config")
    public String nodeConfig(HttpServletRequest request) {
        Set<NodeConfig> nodeConfigs = super.nodeService().query();
        request.setAttribute("nodes", nodeConfigs);
        return "node-config";
    }

    @RequestMapping("env-config")
    public String envConfig(HttpServletRequest request) {
        Set<NodeConfig> nodeConfigs = super.envService().query();
        request.setAttribute("envs", nodeConfigs);
        return "env-config";
    }

    @RequestMapping("acv-config")
    public String acvConfig(HttpServletRequest request) {
        Set<NodeMultiConfig> nodeConfigs = super.acvService().query();
        request.setAttribute("acvs", nodeConfigs);
        return "acv-config";
    }

    @RequestMapping("data-config")
    public String dataConfig(HttpServletRequest request) {
        List<MetaDataConfig> metaDataConfigs = super.opsService().search(new MetaConfig(), null);
        request.setAttribute("configs", metaDataConfigs);
        return "data-config";
    }

    @RequestMapping("limiter-configs")
    public String limiterConfigs(HashMap<String, Object> map) {
        return "limiter-configs";
    }

    @RequestMapping("limiter-config")
    public String limiterConfig(HashMap<String, Object> map) {
        return "limiter-config";
    }

    @RequestMapping("limiter-monitor")
    public String limiterMonitor(HashMap<String, Object> map) {
        return "limiter-monitor";
    }

    @RequestMapping("degrade-configs")
    public String degradeConfigs(HashMap<String, Object> map) {
        return "degrade-configs";
    }

    @RequestMapping("degrade-config")
    public String degradeConfig(HashMap<String, Object> map) {
        return "degrade-config";
    }

}
